import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:使用一下线程池
 * User: rei
 * Date: 2025-11-12
 * Time: 20:41
 */
public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);

        for (int i = 0 ; i<10;i++){
            int taskId = i + 1;
        threadPool.submit(() ->{
            System.out.println("执行任务 : " + taskId + ", " + Thread.currentThread().getName());
        });

        TimeUnit.SECONDS.sleep(1);
        }
        //test
        //不用start方法,自己创建了线程
    }
}
